using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 分类应用服务接口
    /// 提供内容分类管理的业务逻辑
    /// </summary>
    public interface ICategoryAppService
    {
        /// <summary>
        /// 获取分页的分类列表
        /// </summary>
        /// <param name="query">查询参数</param>
        /// <returns>分页的分类列表</returns>
        Task<PagedResultDto<CategoryDto>> GetPagedListAsync(PagedQueryDto query);
        
        /// <summary>
        /// 获取树形分类列表
        /// </summary>
        /// <param name="type">分类类型</param>
        /// <param name="parentId">父分类ID</param>
        /// <returns>树形分类列表</returns>
        Task<List<CategoryDto>> GetTreeAsync(string? type = null, long? parentId = null);
        
        /// <summary>
        /// 根据类型获取分类列表
        /// </summary>
        /// <param name="type">分类类型</param>
        /// <returns>分类列表</returns>
        Task<List<CategoryDto>> GetByTypeAsync(string type);
        
        /// <summary>
        /// 根据ID获取分类详情
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <returns>分类详情</returns>
        Task<CategoryDto?> GetByIdAsync(long id);
        
        /// <summary>
        /// 根据路径获取分类
        /// </summary>
        /// <param name="path">分类路径</param>
        /// <returns>分类信息</returns>
        Task<CategoryDto?> GetByPathAsync(string path);
        
        /// <summary>
        /// 创建分类
        /// </summary>
        /// <param name="dto">分类数据</param>
        /// <returns>创建的分类</returns>
        Task<CategoryDto> CreateAsync(CategoryDto dto);
        
        /// <summary>
        /// 更新分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <param name="dto">更新的分类数据</param>
        /// <returns>更新后的分类</returns>
        Task<CategoryDto> UpdateAsync(long id, CategoryDto dto);
        
        /// <summary>
        /// 删除分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <param name="deleteChildren">是否删除子分类</param>
        /// <returns>删除结果</returns>
        Task<bool> DeleteAsync(long id, bool deleteChildren = false);
        
        /// <summary>
        /// 批量删除分类
        /// </summary>
        /// <param name="ids">分类ID列表</param>
        /// <param name="deleteChildren">是否删除子分类</param>
        /// <returns>删除结果</returns>
        Task<bool> BatchDeleteAsync(List<long> ids, bool deleteChildren = false);
        
        /// <summary>
        /// 移动分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <param name="newParentId">新父分类ID</param>
        /// <returns>移动结果</returns>
        Task<bool> MoveAsync(long id, long? newParentId);
        
        /// <summary>
        /// 获取分类的子分类
        /// </summary>
        /// <param name="parentId">父分类ID</param>
        /// <param name="includeDisabled">是否包含禁用的分类</param>
        /// <returns>子分类列表</returns>
        Task<List<CategoryDto>> GetChildrenAsync(long parentId, bool includeDisabled = false);
        
        /// <summary>
        /// 获取分类的所有祖先分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <returns>祖先分类列表</returns>
        Task<List<CategoryDto>> GetAncestorsAsync(long id);
        
        /// <summary>
        /// 获取分类的所有后代分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <returns>后代分类列表</returns>
        Task<List<CategoryDto>> GetDescendantsAsync(long id);
        
        /// <summary>
        /// 检查分类名称是否存在
        /// </summary>
        /// <param name="name">分类名称</param>
        /// <param name="type">分类类型</param>
        /// <param name="parentId">父分类ID</param>
        /// <param name="excludeId">排除的分类ID</param>
        /// <returns>是否存在</returns>
        Task<bool> ExistsAsync(string name, string type, long? parentId = null, long? excludeId = null);
        
        /// <summary>
        /// 更新分类内容统计
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <returns>更新结果</returns>
        Task<bool> UpdateContentCountAsync(long id);
        
        /// <summary>
        /// 批量更新排序权重
        /// </summary>
        /// <param name="sortData">排序数据</param>
        /// <returns>更新结果</returns>
        Task<bool> BatchUpdateSortAsync(Dictionary<long, int> sortData);
        
        /// <summary>
        /// 启用/禁用分类
        /// </summary>
        /// <param name="id">分类ID</param>
        /// <param name="enabled">是否启用</param>
        /// <returns>操作结果</returns>
        Task<bool> SetEnabledAsync(long id, bool enabled);
        
        /// <summary>
        /// 导出分类数据
        /// </summary>
        /// <param name="type">分类类型</param>
        /// <returns>导出数据</returns>
        Task<byte[]> ExportAsync(string? type = null);
        
        /// <summary>
        /// 导入分类数据
        /// </summary>
        /// <param name="data">导入数据</param>
        /// <returns>导入结果</returns>
        Task<List<CategoryDto>> ImportAsync(byte[] data);
    }
}
